<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUniqueIdToWaimaiOrderDetailTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $cFunc = function (Blueprint $table) {
            $table->string('uniqueId', 48)->default('')->comment('饿了么:每个订单内菜品的唯一id');
            $table->string('skuId', 24)->default('')->comment('skuId');
            $table->unsignedSmallInteger('partRefundNum')->default(0)->comment('部分退款数量');
        };


        $cFunc1 = function (Blueprint $table) {
            $table->tinyInteger('isPartRefund')->default(0)->comment('是否部分退款 0否 1是');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlWaiMai")->table('waimai_order_details' . $this->name, $cFunc);
            Schema::connection("mysqlWaiMai_2")->table('waimai_order_details' . $this->name, $cFunc);

            Schema::connection("mysqlWaiMai")->table('waimai_orders' . $this->name, $cFunc1);
            Schema::connection("mysqlWaiMai_2")->table('waimai_orders' . $this->name, $cFunc1);
            dump($this->name . '已添加');
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $cFunc = function (Blueprint $table) {
            $table->dropColumn('uniqueId');
            $table->dropColumn('skuId');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlWaiMai")->table('waimai_order_details' . $this->name, $cFunc);
            Schema::connection("mysqlWaiMai_2")->table('waimai_order_details' . $this->name, $cFunc);
            dump($this->name . '已添加');
        }
    }
}
